# --coding:utf-8--
import os
import time
import platform

from Implement.LinuxFileIconProvider import LinuxFileIconProvider
from Implement.WinFileIconProvider import WinFileIconProvider
from Interface.ISearchResult import ISearchResult
plat = platform.system()
class SearchResultImpl(ISearchResult):
    __iconprovider = None
    def __init__(self,filePath):
        if not os.path.exists(filePath):
            raise OSError
        self.__fileName = os.path.basename(filePath)
        self.__filePath = filePath
    def getIconProvider(self):
        if  self.__iconprovider == None:
            if plat == "Windows":
                self.__iconprovider = WinFileIconProvider(self.__filePath)
            '''
            elif plat == "Linux":
                self.__iconprovide = LinuxFileIconProvider(self.__filePath)
            todo:
            其他平台的实现
            '''
        return  self.__iconprovider
    def getFileName(self):
        return self.__fileName

    def getFilePath(self):
        return self.__filePath

    def getFileSize(self):
            return os.path.getsize(self.__filePath)
    def getCreateTime(self):
            return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(os.path.getctime(self.__filePath)))
    def getLastModify(self):
        return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(os.path.getmtime(self.__filePath)))

    def getAbstract(self):
        raise NotImplementedError
    def getKeyWords(self):
        raise NotImplementedError